package com.tina.controller;

import org.apache.rocketmq.client.producer.SendResult;
import org.apache.rocketmq.common.message.Message;
import org.apache.rocketmq.spring.core.RocketMQTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Author tina
 * @Time 2020/11/23 上午9:47
 * @Version 1.0
 * @Content
 **/
@RestController
public class MqController {
    @Autowired
    private RocketMQTemplate rocketMQTemplate;

    @GetMapping("send")
    public SendResult send() throws Exception {
        return sendCancelOrder("test", "112", "key", "Test MQ SEND Msg");
    }

    /**
     * 发送订单确认失败消息
     *
     * @param topic
     * @param tag
     * @param keys
     * @param body
     */
    private SendResult sendCancelOrder(String topic, String tag, String keys, String body) throws Exception {
        Message message = new Message(topic, tag, keys, body.getBytes());
        return rocketMQTemplate.getProducer().send(message);
    }
}
